# reference: http://tog.acm.org/resources/GraphicsGems/gemsiv/ptpoly_haines
def is_pt_in_poly_2d(pt, poly):
	inside = False
	n = mgCountChild(poly)
	if (n > 1):
		vertex = mgGetChildNth(poly, n)
		ok, x, y, z = mgGetVtxCoord(vertex)
		prev_pt = mgMakeCoord2d(x, y)
		is_prev_pt_above_pt = (prev_pt.y >= pt.y)
		vertex = mgGetChild(poly)
		while vertex:
			ok, x, y, z = mgGetVtxCoord(vertex)
			this_pt = mgMakeCoord2d(x, y)
			is_this_pt_above_pt = (this_pt.y >= pt.y)
			if (is_prev_pt_above_pt != is_this_pt_above_pt):
				b = ((this_pt.y - pt.y) * (prev_pt.x - this_pt.x) >= (this_pt.x - pt.x) * (prev_pt.y - this_pt.y))
				if (b == is_this_pt_above_pt):
					inside = not inside
			is_prev_pt_above_pt = is_this_pt_above_pt
			prev_pt = this_pt
			vertex = mgGetNext(vertex)
	return inside